<template>
	<view>
		<!-- 审核 -->
		<u-popup :show="shVisible" @close="close('company_receiptReviewPassed')" round="10" closeable>
			<view class="popup-title" v-if="oper_item.payment_status == 1">付款一审</view>
			<view class="popup-title" v-if="oper_item.payment_status == 3">付款二审</view>
			<view class="popup-title" v-if="oper_item.payment_status == 4">付款三审</view>
			<view class="popup-title" v-if="oper_item.payment_status == 5">付款确认</view>
			<view class="popup-box">
				<u-radio-group v-if="oper_item.payment_status != 5" v-model="collectionPaymentsFormInline.reviewPassed"
					placement="row" activeColor="#3B75FF">
					<u-radio :name="1" label="通过" :customStyle="{ marginRight: '40rpx' }"></u-radio>
					<u-radio :name="2" label="拒绝"></u-radio>
				</u-radio-group>
				<view class="textarea-box">
					<u-textarea v-model="collectionPaymentsFormInline.desc" placeholder="请输入审批意见"></u-textarea>
				</view>
				<u-button type="primary" text="提交" color="#3B75FF" :customStyle="{ marginTop: '30rpx' }"
					@click="shSubmit"></u-button>
			</view>
		</u-popup>
	</view>
</template>

<script>
	export default {
		name: 'paymentOperate',
		props: {
			value: {
				type: String,
				default: ''
			},
			oper_item: {
				type: Object,
				default: {}
			}
		},
		data() {
			return {
				collectionPaymentsFormInline: {
					reviewPassed: 1,
					desc: ''
				},
				shVisible: false
			};
		},
		watch: {
			value(val) {
				switch (val) {
					// 一审
					case 'gck_gcjlsh':
						this.shVisible = true;
						break;
					case 'gystk_gcbjlsh':
						this.shVisible = true;
						break;
					case 'zxtk_khzjsh':
						this.shVisible = true;
						break;
						// 二审
					case 'gck_zjysh':
						this.shVisible = true;
						break;
					case 'gystk_zjlsh':
						this.shVisible = true;
						break;
					case 'zxtk_zjysh':
						this.shVisible = true;
						break;
						// 三审
					case 'gck_cwsh':
						this.shVisible = true;
						break;
					case 'gystk_cwsh':
						this.shVisible = true;
						break;
					case 'zxtk_cwsh':
						this.shVisible = true;
						break;
						// 付款确认
					case 'gck_cnsh':
						this.shVisible = true;
						break;
					case 'gystk_cnsh':
						this.shVisible = true;
						break;
					case 'zxtk_cnsh':
						this.shVisible = true;
						break;
						// 重新提交
					case 'fkd_edit':
						uni.navigateTo({
							url: '/pagesC/collectionManagement/addPayment/addPayment?id=' + this.oper_item.id,
							success: (res) => {
								res.eventChannel.emit('sendData', this.oper_item);
							}
						});
						this.close();
						break;

					default:
				}
			}
		},
		methods: {
			close(type) {
				if (type) {
					this.shVisible = false;
				}
				this.collectionPaymentsFormInline = {
					reviewPassed: 1,
					desc: ''
				};
				this.$emit('update:value', '');
			},
			shSubmit() {
				let that = this;
				let collectionPaymentsFormInline = that.collectionPaymentsFormInline;
				// 付款确认
				if (that.oper_item.payment_status == 5) {
					uni.showModal({
						title: '提示',
						content: '确认该付款单已付款?',
						showCancel: true,
						success(res) {
							if (res.confirm) {
								that.updatePaymentSuccess({
									payment_id: that.oper_item.id,
									payment_status: that.oper_item.payment_status,
									pay_type: that.oper_item.pay_type,
									refuse_desc: collectionPaymentsFormInline.desc
								});
							}
						}
					});
					return;
				}
				// 审核
				switch (collectionPaymentsFormInline.reviewPassed) {
					case 1:
						that.updatePaymentSuccess({
							payment_id: that.oper_item.id,
							payment_status: that.oper_item.payment_status,
							pay_type: that.oper_item.pay_type,
							refuse_desc: collectionPaymentsFormInline.desc
						});
						break;
					case 2:
						if (!collectionPaymentsFormInline.desc) {
							uni.showToast({
								title: '请输入拒绝原因',
								icon: 'error'
							});
							return;
						}
						that.updatePaymentRefuse({
							payment_id: that.oper_item.id,
							payment_status: that.oper_item.payment_status,
							pay_type: that.oper_item.pay_type,
							refuse_desc: collectionPaymentsFormInline.desc
						});
						break;
					default:
				}
			},
			// 审核通过(付款单)
			updatePaymentSuccess(obj) {
				uni.showLoading({
					mask: true
				});
				this.$Apipc.updatePaymentSuccess(obj).then((res) => {
					console.log(res, '审核通过(付款单)');
					uni.hideLoading();
					if (res.code == 200) {
						this.close('updatePaymentSuccess');
						this.$emit('submit', this.value);
					}
					uni.showToast({
						icon: res.code == 200 ? 'success' : 'error',
						title: res.message
					});
				});
			},
			// 审核拒绝(付款单)
			updatePaymentRefuse(obj) {
				uni.showLoading({
					mask: true
				});
				this.$Apipc.updatePaymentRefuse(obj).then((res) => {
					console.log(res, '审核拒绝(付款单)');
					uni.hideLoading();
					if (res.code == 200) {
						this.close('updatePaymentRefuse');
						this.$emit('submit', this.value);
					}
					uni.showToast({
						icon: res.code == 200 ? 'success' : 'error',
						title: res.message
					});
				});
			}
		}
	};
</script>

<style lang="scss">
	.popup-title {
		height: 46px;
		border-bottom: 2rpx solid #efefef;
		text-align: center;
		line-height: 46px;
		font-size: 30rpx;
	}

	.popup-box {
		padding: 30rpx 20rpx 20rpx;

		.textarea-box {
			margin-top: 30rpx;
		}
	}
</style>